#include <bits/stdc++.h>

using namespace std;

struct milker{
    int price , m;
}mk[5010];
bool cmp(milker a, milker b){
    return a.price<b.price;
}
int w,n,ans;
int main()
{
    cin>>w>>n;
    for(int i = 1;i<=n;i++){
        cin>>mk[i].price>>mk[i].m;
    }
    sort(mk+1,mk+n+1,cmp);
    int i = 1;
    while(w>0){
       if(mk[i].m<=w){
        ans += mk[i].m*mk[i].price;
        w-=mk[i].m;
       }else{
        ans += w*mk[i].price;
        w-=w;
       }
       i++;
    }
    cout<<ans;
    return 0;
}
